using System;
using System.ComponentModel;
using System.Transactions;

using SIS.ENT;
using SIS.DAL;


namespace SIS.BLL
{

    /// <summary>
    /// The SchoolProfileTableManager class is responsible for managing BO.SchoolProfileTable objects in the system.
    /// </summary>
    [DataObjectAttribute()]
    public class SchoolProfileTableManager
    {

        #region "Public Methods"

        /// <summary>
        /// Gets a list with all SchoolProfileTable objects in the database.
        /// </summary>
        /// <returns>A list with all SchoolProfileTable from the database when the database contains any, or null otherwise.</returns>
        [DataObjectMethod(DataObjectMethodType.Select, true)]
        public static SchoolProfileTableList GetList()
        {
            return SchoolProfileTableDB.GetList();
        }

        /// <summary>
        /// Gets a single SchoolProfileTable from the database without its data.
        /// </summary>
        /// <param name="schoolKey">The SchoolKey of the SchoolProfileTable in the database.</param>
        /// <returns>A SchoolProfileTable object when the SchoolKey exists in the database, or <see langword="null"/> otherwise.</returns>
        [DataObjectMethod(DataObjectMethodType.Select, false)]
        public static SchoolProfileTable GetItem(int schoolKey)
        {
            return GetItem(schoolKey, false);
        }

        /// <summary>
        /// Gets a single SchoolProfileTable from the database.
        /// </summary>
        /// <param name="schoolKey">The SchoolKey of the SchoolProfileTable in the database.</param>
        /// <param name="getSchoolProfileTableRecords">Determines whether to load all associated SchoolProfileTable records as well.</param>
        /// <returns>
        /// A SchoolProfileTable object when the SchoolKey exists in the database, or <see langword="null"/> otherwise.
        /// </returns>
        [DataObjectMethod(DataObjectMethodType.Select, false)]
        public static SchoolProfileTable GetItem(int schoolKey, bool getSchoolProfileTableRecords)
        {
            SchoolProfileTable mySchoolProfileTable = SchoolProfileTableDB.GetItem(schoolKey);
            if (mySchoolProfileTable != null && getSchoolProfileTableRecords)
            {
                mySchoolProfileTable.schoolAddressTables = SchoolAddressTableDB.GetListBySchoolKey(schoolKey);
            }
            if (mySchoolProfileTable != null && getSchoolProfileTableRecords)
            {
                mySchoolProfileTable.schoolContactTables = SchoolContactTableDB.GetListBySchoolKey(schoolKey);
            }
            return mySchoolProfileTable;
        }

        /// <summary>
        /// Saves a SchoolProfileTable in the database.
        /// </summary>
        /// <param name="mySchoolProfileTable">The SchoolProfileTable instance to save.</param>
        /// <returns>The new SchoolKey if the SchoolProfileTable is new in the database or the existing SchoolKey when an item was updated.</returns>
        [DataObjectMethod(DataObjectMethodType.Update, true)]
        public static int Save(SchoolProfileTable mySchoolProfileTable)
        {
            using (TransactionScope myTransactionScope = new TransactionScope())
            {
                int schoolProfileTableSchoolKey = SchoolProfileTableDB.Save(mySchoolProfileTable);
                //foreach (SchoolAddressTable mySchoolAddressTable in mySchoolProfileTable.schoolAddressTables){
                //mySchoolAddressTable.SchoolKey = schoolProfileTableSchoolKey;
                //SchoolAddressTableDB.Save(mySchoolAddressTable);
                //}
                //foreach (SchoolContactTable mySchoolContactTable in mySchoolProfileTable.schoolContactTables){
                //mySchoolContactTable.SchoolKey = schoolProfileTableSchoolKey;
                //SchoolContactTableDB.Save(mySchoolContactTable);
                //}

                //  Assign the SchoolProfileTable its new (or existing SchoolKey).
                mySchoolProfileTable.SchoolKey = schoolProfileTableSchoolKey;

                myTransactionScope.Complete();

                return schoolProfileTableSchoolKey;
            }
        }

        /// <summary>
        /// Deletes a SchoolProfileTable from the database.
        /// </summary>
        /// <param name="mySchoolProfileTable">The SchoolProfileTable instance to delete.</param>
        /// <returns>Returns true when the object was deleted successfully, or false otherwise.</returns>
        [DataObjectMethod(DataObjectMethodType.Delete, true)]
        public static bool Delete(SchoolProfileTable mySchoolProfileTable)
        {
            return SchoolProfileTableDB.Delete(mySchoolProfileTable.SchoolKey);
        }


        /// <summary>
        /// Update Logo a SchoolProfileTable from the database.
        /// </summary>
        /// <param name="mySchoolProfileTable">The SchoolProfileTable instance to delete.</param>
        /// <returns>Returns true when the object was deleted successfully, or false otherwise.</returns>
        public static bool UpdateLogo(int SchoolKey, Byte[] imgLogo)
        {
            return SchoolProfileTableDB.UpdateLogo(SchoolKey, imgLogo);
        }


        /// <summary>
        /// Update Photo a SchoolProfileTable from the database.
        /// </summary>
        /// <param name="mySchoolProfileTable">The SchoolProfileTable instance to delete.</param>
        /// <returns>Returns true when the object was deleted successfully, or false otherwise.</returns>
        public static bool UpdatePhoto(int SchoolKey, Byte[] imgPhoto)
        {
            return SchoolProfileTableDB.UpdatePhoto(SchoolKey, imgPhoto);
        }

        /// <summary>
        /// Get Logo a SchoolProfileTable from the database.
        /// </summary>
        /// <param name="mySchoolProfileTable">The SchoolProfileTable instance to delete.</param>
        /// <returns>Returns true when the object was deleted successfully, or false otherwise.</returns>
        public static Byte[] GetLogo(int SchoolKey)
        {
            return SchoolProfileTableDB.GetLogo(SchoolKey);
        }

        /// <summary>
        /// Get Photo a SchoolProfileTable from the database.
        /// </summary>
        /// <param name="mySchoolProfileTable">The SchoolProfileTable instance to delete.</param>
        /// <returns>Returns true when the object was deleted successfully, or false otherwise.</returns>
        public static Byte[] GetPhoto(int SchoolKey)
        {
            return SchoolProfileTableDB.GetPhoto(SchoolKey);
        }

        #endregion

    }

}
